
package org.apache.mina.common;

import org.apache.mina.common.support.DefaultExceptionMonitor;

/**
 * Monitors uncaught exceptions. {@link #exceptionCaught(Throwable)} is invoked
 * when there are any uncaught exceptions.
 * 监视未捕获的异常。当有任何的未捕获异常时，会调用exceptionCaught(Throwable)方法。
 * <p>
 * You can monitor any uncaught exceptions by setting {@link ExceptionMonitor}
 * by calling {@link #setInstance(ExceptionMonitor)}. The default monitor logs
 * all caught exceptions in <tt>WARN</tt> level using SLF4J.
 * 
 * 你可以通过调用setInstance(ExceptionMonitor)方法来设置ExceptionMonitor，用来监视任意的未异常。
 * 默认的监视器用SLF4J记录所有的WARN级别的未捕获异常。
 * 
 * @see DefaultExceptionMonitor
 */
public abstract class ExceptionMonitor {
    private static ExceptionMonitor instance = new DefaultExceptionMonitor();

    /**
     * Returns the current exception monitor.
     * 
     * 返回当前的异常监视器。
     */
    public static ExceptionMonitor getInstance() {
        return instance;
    }

    /**
     * Sets the uncaught exception monitor. If <code>null</code> is specified,
     * the default monitor will be set.
     * 
     * 设置未捕获异常监视器。如果monitor是null，则会设置为默认的监视器：DefaultExceptionMonitor。
     * 
     * @param monitor
     *            A new instance of {@link DefaultExceptionMonitor} is set if
     *            <tt>null</tt> is specified.
     */
    public static void setInstance(ExceptionMonitor monitor) {
        if (monitor == null) {
            monitor = new DefaultExceptionMonitor();
        }
        instance = monitor;
    }

    /**
     * Invoked when there are any uncaught exceptions.
     * 
     * 当有任何的未捕获异常时，会调用此方法。
     */
    public abstract void exceptionCaught(Throwable cause);
}